package com.controller.library;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.library.GeneratePaperAction;
import com.bean.library.Paper;

public class TCheckPaperContentServlet extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 7956009078378998917L;

	public void doPost(HttpServletRequest request,HttpServletResponse response){
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		if(request.getSession().getAttribute("selectedCourseId")!=null){
			int paperId = Integer.parseInt(request.getParameter("paper_id"));
			GeneratePaperAction generatePaperAction = new GeneratePaperAction();
			Paper paper = null;
			try{
				paper = generatePaperAction.generateStandardPaper(paperId);
			}catch(Exception ex){
				ex.printStackTrace();
			}
			request.getSession().setAttribute("paper", paper);
			Paper partialPaper = new Paper();
			try{
				partialPaper.setPaperName(paper.getPaperName());
				partialPaper.setSubjectList(paper.getSubjectList(0, 10));
			}catch(Exception e){
				e.printStackTrace();
			}
			request.getSession().setAttribute("partialPaper", partialPaper);
			try {
				response.sendRedirect("/Exam1/teacher/t_page/t_paper_content.jsp");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
